/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.sys.web.user;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.sys.entity.user.HkUserAlbum;
import com.thinkgem.jeesite.modules.hk.sys.service.user.HkUserAlbumService;

/**
 * 用户相册Controller
 * @author 罗天文
 * @version 2018-03-29
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/user/hkUserAlbum")
public class HkUserAlbumController extends BaseController {

	@Autowired
	private HkUserAlbumService hkUserAlbumService;
	
	@ModelAttribute
	public HkUserAlbum get(@RequestParam(required=false) String id) {
		HkUserAlbum entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkUserAlbumService.get(id);
		}
		if (entity == null){
			entity = new HkUserAlbum();
		}
		return entity;
	}
	
	@RequiresPermissions("sys:user:hkUserAlbum:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkUserAlbum hkUserAlbum, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkUserAlbum> page = hkUserAlbumService.findPage(new Page<HkUserAlbum>(request, response), hkUserAlbum); 
		model.addAttribute("page", page);
		return "hk/sys/user/hkUserAlbumList";
	}

	@RequiresPermissions("sys:user:hkUserAlbum:view")
	@RequestMapping(value = "form")
	public String form(HkUserAlbum hkUserAlbum, Model model) {
		model.addAttribute("hkUserAlbum", hkUserAlbum);
		return "hk/sys/user/hkUserAlbumForm";
	}

	@RequiresPermissions("sys:user:hkUserAlbum:edit")
	@RequestMapping(value = "save")
	public String save(HkUserAlbum hkUserAlbum, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkUserAlbum)){
			return form(hkUserAlbum, model);
		}
		hkUserAlbumService.save(hkUserAlbum);
		addMessage(redirectAttributes, "保存用户相册成功");
		return "redirect:"+Global.getAdminPath()+"/sys/user/hkUserAlbum/?repage";
	}
	
	@RequiresPermissions("sys:user:hkUserAlbum:edit")
	@RequestMapping(value = "delete")
	public String delete(HkUserAlbum hkUserAlbum, RedirectAttributes redirectAttributes) {
		hkUserAlbumService.delete(hkUserAlbum);
		addMessage(redirectAttributes, "删除用户相册成功");
		return "redirect:"+Global.getAdminPath()+"/sys/user/hkUserAlbum/?repage";
	}

}